export default {
  props: {

  },
  data () {
    return {
      dictionaries: { // 字典数据
        export_model_url: [], // 模板链接
        sale_status: [], // 状态
        goods_type: [] // 商品类型
      },
      parArray: [] // 按钮权限
    }
  },
  computed: {

  },
  created () {
    // 获取字典值
    for (const type in this.dictionaries) { this.getDictionaries(type) }
  },
  methods: {
    // 获取字典数据
    getDictionaries (type) {
      if (type && this.dictionaries[type].length > 0) {
        return
      }
      const params = { groupId: type }
      this.$api.dictionaries(params).then((res) => {
        this.dictionaries[type] = res.data
        const sessionObj = JSON.parse(sessionStorage.getItem('dictionaries'))
        let tempObj
        if (sessionObj) {
          tempObj = Object.assign(sessionObj, this.dictionaries)
        } else {
          tempObj = this.dictionaries
        }
        sessionStorage.removeItem('dictionaries')
        sessionStorage.setItem('dictionaries', JSON.stringify(tempObj))
      }).catch((err) => {
        console.log(err)
      })
    },
    getButtonTreeDto () {
      // 获取权限设定
      this.limits = JSON.parse(sessionStorage.getItem('limit'))
      const params = this.limits.buttonTreeDto.filter((item) => item.menuCode === 'companyCode')
      params[0].buttonList.forEach((item) => { this.parArray.push(item.code) })
      console.log(this.parArray)
    },
    // 重置表单
    resetForm (formName) { this.$refs[formName].resetFields() },
    // 页面跳转
    toOtherPages (name, parameter, type) {
      let query = { id: parameter, type }
      if (type === 'category') { query = { category: parameter, type } }
      this.$router.push({ name, query })
    }
  }
}
